// mycomponent/Waterfalls_flow.js
var app = getApp();
Page({
  options: {
    styleIsolation: 'shared',
  },
  data:{
    pagename:'',
    listPaddingHeight:'',
    search_type:'',
    list:[],
    keyword:'',
    offset:0,
    limit:10,
    page:0,
    count:null
  },
  tabClick(e){
    let type = e.currentTarget.dataset.type
    let indexs = e.currentTarget.dataset.index
    this.data.list.forEach((item,index)=>{
      if(indexs == index){
        item.tabIndex = type
      }
    })
    this.setData({
      list:this.data.list
    })
  },
  getHeight: function() {
    var query = wx.createSelectorQuery();
    query.select('#box').boundingClientRect(data => {
      if (data) {
        console.log(data.height); // 元素的高度
        let boxHeight = data.height
        // let windowHeight = wx.getSystemInfoSync().windowHeight
        this.setData({
          listPaddingHeight:boxHeight
        })
      }
    }).exec();
  },
  getList(){
    let urlStr = app.getNetAddresss("plugin.company-manage.frontend.store.zhangLv.getDistributionStatisticList");
    app._getNetWork({
      url: urlStr,
      data: {keyword:this.data.keyword,search_type:this.data.search_type,limit:this.data.limit,offset:this.data.offset},
      success: (resdata) => {
        console.log(resdata,'-----------resdata')
        if (resdata.data.result == 1) {
          if(resdata.data.data.list.length != 0){
            resdata.data.data.list.forEach((item)=>{
              item['tabIndex'] = 1
            })
          }
          this.setData({
            count:resdata.data.data.count,
            list:this.data.list.concat(resdata.data.data.list)
          })
        }
      }
    })
  },
  onChange(e){
    this.setData({
      keyword: e.detail,
    });
  },
  search(){
    console.log(this.data.keyword)
    this.setData({
      page:0,
      offset:0,
      List:[]
    })
    this.getList()
  },
  onLoad(options){
    console.log(options)
    this.setData({
      typename:options.typename
    })
    if(this.data.typename == '旅行社订单'){
      wx.setNavigationBarTitle({
        title: '旅行社订单'
      })
      this.setData({
        search_type:'travel-agency'
      })
    } else if(this.data.typename == '门店订单'){
      wx.setNavigationBarTitle({
        title: '门店订单' 
      })
      this.setData({
        search_type:'store'
      })
    } else if(this.data.typename == '找导游订单'){
      wx.setNavigationBarTitle({
        title: '导游订单' 
      })
      this.setData({
        search_type:'guide'
      })
    } else if(this.data.typename == '酒店普通订单'){
      wx.setNavigationBarTitle({
        title: '酒店普通订单' 
      })
      this.setData({
        search_type:'hotel-normal'
      })
    } else if(this.data.typename == '酒店升级订单'){
      wx.setNavigationBarTitle({
        title: '酒店升级订单' 
      })
      this.setData({
        search_type:'hotel-upgrade'
      })
    } else {
      wx.setNavigationBarTitle({
        title: '平台自营订单' 
      })
      this.setData({
        search_type:'platform'
      })
    }
    this.getList()
  },
  onReady(){
    this.getHeight()
  },
  onShow(){
    
  },
  onHide(){

  },
  onUnload(){

  },
  onPullDownRefresh(){

  },
  onReachBottom(){
    if(this.data.list.length == this.data.count){
      return false
    }
    this.setData({
      page:this.data.page +=1
    })
    this.setData({
      offset:this.data.page*this.data.limit,
    })
    this.getList()
  },
  onShareAppMessage(){
    
  },
})
